#pragma once

#include "Manager.h"

namespace STD_Voorbeeld_Vat 
{

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for LiftForm
	/// </summary>
	public ref class LiftForm : public System::Windows::Forms::Form
	{
	
		public: Manager *manager;

		public:
		LiftForm(void)
		{
			InitializeComponent();
			
			/*
			Elevator *elevator = elevatorConstruct();
			elevatorSendEvent(elevator, openingDoor);
			elevatorSendEvent(elevator, closingDoor);
			elevatorSendEvent(elevator, nextDestination);
			elevatorSendEvent(elevator, movingUp);
			elevatorSendEvent(elevator, stopping);

			Shaft *shaft;

			Shaft *firstShaft = shaftConstruct(0, 10);
			Shaft *secondShaft = shaftConstruct(0, 8);
			manager = managerConstructWithShaft(firstShaft);
			managerAddShaft(manager, secondShaft);
			Destination *destination = destinationConstruct(4, 0); // Floor: 4, Prio: None
			
			shaft = managerSelectShaftForDispatch(manager, destination);
			shaftAddDestination(shaft, destination);

			Elevator *elevator = shaft->elevator;
			elevatorSendEvent(elevator, openingDoor);
			elevatorSendEvent(elevator, closingDoor);
			elevatorSendEvent(elevator, nextDestination);
			elevatorSendEvent(elevator, movingUp);
			elevatorSendEvent(elevator, stopping);
			*/
		}

		private: System::Void instantiateSystem_CLICK(System::Object^  sender, System::EventArgs^  e) 
		{
			// SHAFT MAINTENANCE
			if (manager != NULL) 
				managerDeconstruct(manager);

			int i = 0;
			Shaft *shaft;

			if (numOfElevators->Value > 0)
			{
				shaft = shaftConstruct(0, (int) numOfFloors->Value);
				manager = managerConstructWithShaft(shaft);

				if ((int) numOfElevators->Value > 1)
				{
					for (i = 1; i < (int) numOfElevators->Value; i++)
					{
						shaft = shaftConstruct(0, (int) numOfFloors->Value);
						managerAddShaft(manager, shaft);
					}
				}
			}

			// MANAGER IS NU EPISCH KLAAR
			Destination *destination = destinationConstruct((int)numOfFloors->Value - 1, 0);
			shaft = managerSelectShaftForDispatch(manager, destination); // op dit punt hebben we een shaft  die ergens heen kan
			shaftAddDestination(shaft, destination);

			Elevator *elevator = shaft->elevator;

			elevatorSendEvent(elevator, openingDoor); // kastje open
			elevatorSendEvent(elevator, closingDoor); // kastje dicht
			elevatorSendEvent(elevator, nextDestination); // VROEM naar nieuwe plekzor
			elevatorSendEvent(elevator, move);	// en de lift begint te bewegen
			elevatorSendEvent(elevator, stopping); // komt aan op locatie
			elevatorSendEvent(elevator, openingDoor); // opent deur en laat mensen er uit / er in
			elevatorSendEvent(elevator, closingDoor); // sluit deuren en gaat idlen OF naar nieuwe destination


		}


#pragma region GENERATED
	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~LiftForm()
		{
			if (components)
			{
				delete components;
				managerDeconstruct(manager);
			}
		}
	private: System::Windows::Forms::NumericUpDown^  numOfElevators;
	protected: 
	private: System::Windows::Forms::NumericUpDown^  numOfFloors;
	private: System::Windows::Forms::Button^  btn_instantiateSystem;

	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->numOfElevators = (gcnew System::Windows::Forms::NumericUpDown());
			this->numOfFloors = (gcnew System::Windows::Forms::NumericUpDown());
			this->btn_instantiateSystem = (gcnew System::Windows::Forms::Button());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numOfElevators))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numOfFloors))->BeginInit();
			this->SuspendLayout();
			// 
			// numOfElevators
			// 
			this->numOfElevators->Location = System::Drawing::Point(122, 9);
			this->numOfElevators->Name = L"numOfElevators";
			this->numOfElevators->Size = System::Drawing::Size(64, 20);
			this->numOfElevators->TabIndex = 2;
			// 
			// numOfFloors
			// 
			this->numOfFloors->Location = System::Drawing::Point(122, 36);
			this->numOfFloors->Name = L"numOfFloors";
			this->numOfFloors->Size = System::Drawing::Size(64, 20);
			this->numOfFloors->TabIndex = 3;
			// 
			// btn_instantiateSystem
			// 
			this->btn_instantiateSystem->Location = System::Drawing::Point(193, 9);
			this->btn_instantiateSystem->Name = L"btn_instantiateSystem";
			this->btn_instantiateSystem->Size = System::Drawing::Size(56, 47);
			this->btn_instantiateSystem->TabIndex = 4;
			this->btn_instantiateSystem->Text = L"Start";
			this->btn_instantiateSystem->UseVisualStyleBackColor = true;
			this->btn_instantiateSystem->Click += gcnew System::EventHandler(this, &LiftForm::instantiateSystem_CLICK);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(16, 9);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(61, 13);
			this->label1->TabIndex = 5;
			this->label1->Text = L"aantal liften";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(16, 39);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(100, 13);
			this->label2->TabIndex = 6;
			this->label2->Text = L"aantal verdiepingen";
			// 
			// LiftForm
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(325, 117);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->btn_instantiateSystem);
			this->Controls->Add(this->numOfFloors);
			this->Controls->Add(this->numOfElevators);
			this->Name = L"LiftForm";
			this->Text = L"LiftForm";
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numOfElevators))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numOfFloors))->EndInit();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion

#pragma endregion
	};
}
